package com.supermap.business.disaster;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.common.entity.Crop;
import com.supermap.dubbo.api.disaster.entity.DisasterComment;
import com.supermap.dubbo.api.disaster.entity.Disasterpraise;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.disaster.DisasterTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lxs
 * @Title:灾害接口层
 * @Description:
 * @date 2018/3/1  15:30
 */
@Controller
@RequestMapping("DisasterTypeController")
public class DisasterTypeController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(DisasterTypeController.class);

    @Reference(timeout = 10000)
    private DisasterTypeService disasterTypeService;


    /**
     * 当levels为1时，获取大类灾情，当levels为2时，获取具体灾情，当levels为0时，获取灾情以及具体灾情，type＝1时获取自然灾害，type＝2时获取病虫害
     */
    @RequestMapping("/getAllDisasterType")
    @ResponseBody
    public JSONUtil getAllDisasterType(HttpServletRequest request){
        String levels = request.getParameter("levels");
        String type = request.getParameter("type");
        return disasterTypeService.getAllDisasterType(Integer.parseInt(levels),type);
    }
    
    /**
     *根据灾害ID得到所有对应的点赞数
     */
    @RequestMapping("/getDisasterPraiseCount")
    @ResponseBody
   public int  getDisasterPraiseCount(HttpServletRequest request){
        String disasterId=request.getParameter("disasterId");
        return disasterTypeService.getDisasterPraiseCount(Integer.valueOf(disasterId));
    }

    /**
     * 判断是否对改灾情点过赞
     * @param request
     * @return
     */
    @RequestMapping("/getDisasterPraise")
    @ResponseBody
    public boolean getDisasterPraise(HttpServletRequest request){
       String userId=request.getParameter("userId");
        String disasterId=request.getParameter("disasterId");
        return disasterTypeService.getDisasterPraise(Integer.valueOf(userId),Integer.valueOf(disasterId));
    }

    /**
     *添加灾害点赞
     * @param request
     * @param disasterpraise
     * @return
     */
    @RequestMapping("/addDisasterPraise")
    @ResponseBody
    public boolean addDisasterPraise(HttpServletRequest request, Disasterpraise disasterpraise){
       return disasterTypeService.addDisasterPraise(disasterpraise);
    }

    /**
     * 根据灾害ID得到对应下的评论
     * @param request
     * @param disasterId
     * @return
     */
    @RequestMapping("/getAllDisasterCommentByagrInfoId")
    @ResponseBody
    public JSONUtil getAllDisasterCommentByagrInfoId(HttpServletRequest request, int disasterId){
        return disasterTypeService.getAllDisasterCommentByagrInfoId(disasterId);
    }
    @RequestMapping("/addDisasterComment")
    @ResponseBody
    public boolean addDisasterComment(HttpServletRequest request, DisasterComment disasterComment){
        String uid=request.getParameter("uid");
        return disasterTypeService.addDisasterComment(disasterComment,uid);
    }

    /**
     * 根据userId获取的灾情的评论内容详情
     * @param request
     * @param table
     * @return
     */
    @RequestMapping("/getDisAllInfoByUserorAreaCode")
    @ResponseBody
    public Table getDisAllInfoByUserorAreaCode(HttpServletRequest request,Table table){
        String userId=request.getParameter("userId");
        String areaCode=request.getParameter("areaCode");
        JSONUtil jsonUtil=disasterTypeService.getDisAllInfoByUserorAreaCode(table,userId,areaCode);
        table =(Table)jsonUtil.getData();
        table.setMsg(jsonUtil.getMsg());
        table.setCode(jsonUtil.getCode());
        return table;
    }
}
